package org.dragon.mappers;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.dragon.models.Permission;
import org.dragon.models.Role;

import java.util.List;

/**
 * Author:     Zhao Yan
 * DateTime:   2023/5/22 9:07
 */
@Mapper
public interface RoleExtendMapper extends RoleMapper {

    @Select("select r.* from account_role ar left join role r on ar.role_id = r.id where ar.account_id = #{id}")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="code", property="code", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Role> findRoles(@Param("id") String id);

    @Select("select p.* from role_permission rp left join permission p on rp.permission_id = p.id where rp.role_id = #{id}")
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
            @Result(column="code", property="code", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Permission> findPermissions(@Param("id") Long id);
}
